<template>
  <el-dialog
    @open="mixinOpen"
    @close="handleClose"
    :title="title"
    :visible="dialogVisible"
    width="80%"
  >
    <el-form
      :model="postData"
      :rules="postRules"
      label-width="120px"
      label-position="left"
      ref="postForm"
    >
      <el-row>
        <el-col :span="8">
          <el-form-item label="请求内容" prop="content">
            <el-input v-model="postData.content"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="期望租金" prop="rent">
            <el-input v-model="postData.rent"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="租约时间" prop="startTime">
            <el-date-picker
              v-model="rentTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button @click="save" type="primary">发 起</el-button>
    </div>
  </el-dialog>
</template>

<script>
import postDialog from "../../../mixins/postDialog";
// eslint-disable-next-line no-unused-vars
import axios from "axios";

export default {
  name: "postDialog",
  mixins: [postDialog],
  data() {
    return {
      postData: {
        content: "",
        rent: "",
        startTime: "",
        endTime: "",
        houseId: "",
        status: ""
      },
      postRules: {
        content: [{ required: true, message: "请填写内容", trigger: "blur" }],
        rent: [{ required: true, message: "请填写租金", trigger: "blur" }],
        startTime: [
          { required: true, message: "请选择时间", trigger: "submit" }
        ],
        endTime: [{ required: true, message: "请选择时间", trigger: "submit" }]
      },
      addUrl: "/api/ask/ask",
      getDetailUrl: "/api/house/house",
      isAdd: true,
      rentTime: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < new Date().setHours(23, 59, 59);
        }
      }
    };
  },
  methods: {
    save() {
      this.postData.status = 1;
      this.postData.startTime =
        this.rentTime.length === 2 ? this.rentTime[0] : "";
      this.postData.endTime =
        this.rentTime.length === 2 ? this.rentTime[1] : "";
      this.postData.houseId = this.opId;
      this.submit();
    },
    async mixinOpen() {
      await this.handleOpen();
    }
  }
};
</script>

<style scoped></style>
